package com.uifp.gradebook;

import java.io.IOException;

import android.app.ActionBar;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.widget.ListView;
import android.widget.Toast;

import com.uifp.gradebook.adaptors.ClassesCursorAdapter;

public class SearchClassActivity extends ListActivity implements ActionBar.OnNavigationListener{
	
	private ClassesCursorAdapter dataSource;	
	private DataBaseHelper dbHelper = new DataBaseHelper(this);	
			
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_search_class);
        
     	try {
			dbHelper.createDataBase();
		} catch (IOException e) {
			e.printStackTrace();
		}

        Cursor cursorData = dbHelper.getCourses();
        dataSource = new ClassesCursorAdapter(this, cursorData);
        
        setListAdapter(dataSource);
    }

    public void onResume(){
		super.onResume();
		
        Cursor cursorData = dbHelper.getCourses();
        dataSource = new ClassesCursorAdapter(this, cursorData);
        
        setListAdapter(dataSource);
    }
    
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
      super.onListItemClick(l, v, position, id);
      Toast.makeText(this, "Click-" + String.valueOf(position), Toast.LENGTH_SHORT).show();
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.search_activity_actions, menu);
        return (super.onCreateOptionsMenu(menu));
    }

	@Override
	public boolean onNavigationItemSelected(int arg0, long arg1) {
		return false;
	}

}